package com.idTech.items;

import com.idTech.CommonProxy;
import com.idTech.utils.placePositionUtils;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityExpBottle;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class EnemySpawnWand extends Item 
{

    public EnemySpawnWand(int par1)
    {
        super(par1);
        this.setCreativeTab(CreativeTabs.tabMisc);
    }

    @SideOnly(Side.CLIENT)
    public boolean hasEffect(ItemStack par1ItemStack)
    {
        return true;
    }

    /**
     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
     */
    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
    	/*
        if (!par3EntityPlayer.capabilities.isCreativeMode)
        {
            --par1ItemStack.stackSize;
        }
    	*/
        par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

        if (!par2World.isRemote)
        {
        	//par3EntityPlayer.entityDropItem(par1ItemStack, par2)
        	
        	EntitySkeleton skeley = (EntitySkeleton)new EntitySkeleton(par2World);
        	/*
        	skeley.setPosition(par3EntityPlayer.posX, par3EntityPlayer.posY, par3EntityPlayer.posZ);
        	skeley.rotationYaw = par3EntityPlayer.rotationYaw - 90;
        	skeley.posX -= ((double)(MathHelper.cos(skeley.rotationYaw / 180.0F * (float)Math.PI) * 0.16F)) * 100;
            skeley.posZ -= ((double)(MathHelper.sin(skeley.rotationYaw / 180.0F * (float)Math.PI) * 0.16F)) * 100;
            */
        	
        	Vec3 skeyPos = placePositionUtils.placeInFrontOfEntity(par3EntityPlayer, 10);
        	skeley.setPosition(skeyPos.xCoord, skeyPos.yCoord, skeyPos.zCoord);
            par2World.spawnEntityInWorld(skeley);
        }
        

        return par1ItemStack;
    }
    
    public void registerIcons(IconRegister iconReg)
    {
    	itemIcon = iconReg.registerIcon("iDTechModBase:candyStaff");
    	
    }
}